#pragma once
#include <juce_gui_extra/juce_gui_extra.h>
#include <juce_audio_utils/juce_audio_utils.h>
#include <juce_audio_basics/juce_audio_basics.h>
#include "NodeWithButton.h"
#include "NodeWithLabel.h"

class MainComponent : public juce::AudioAppComponent
// class MainComponent : public juce::Component
{
public:
    MainComponent();
    ~MainComponent() override = default;

    void paint(juce::Graphics&) override;
    void resized() override;
    void mouseDown(const juce::MouseEvent& e) override;
    void mouseDrag(const juce::MouseEvent& e) override;
    void mouseUp(const juce::MouseEvent& e) override;
    void mouseMove(const juce::MouseEvent& e) override;
    void mouseWheelMove(const juce::MouseEvent&, const juce::MouseWheelDetails&) override;

    void getNextAudioBlock(const juce::AudioSourceChannelInfo& bufferToFill) override;
    void prepareToPlay (int samplesPerBlockExpected, double newSampleRate) override
    {
        sampleRate = newSampleRate;
        expectedSamplesPerBlock = samplesPerBlockExpected;
    }
    void releaseResources() override
    {
        // This gets automatically called when audio device parameters change
        // or device is restarted.
    }

private:
    std::unique_ptr<juce::Component> contentLayer;
    std::unique_ptr<NodeWithButton> node1;
    std::unique_ptr<NodeWithLabel> node2;
    static constexpr int default_width = 800, default_height = 600;
    juce::Point<float> panOffset { 0, 0 };
    float scale = 1.0f;
    double sampleRate = 0.0;
    int expectedSamplesPerBlock = 0;

    float phase       = 0.0f;
    float phaseDelta  = 0.0f;
    float frequency   = 5000.0f;
    float amplitude   = 0.2f;

    void updateContentTransform();

    // JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MainComponent)
};
